const mongoose = require('mongoose')
const model = mongoose.model.bind(mongoose)
const Schema = mongoose.Schema
const ObjectId = Schema.Types.ObjectId

const roleSchema = new Schema({
   _id: ObjectId,
   roleName: String,
   roleDesc: String,
   rights:[{
    type:ObjectId,
    ref:'Rightance'
   }]
})

const rightanceSchema = new Schema({
    _id:ObjectId,
    rightName:String,
    secondRights:[{
        type:ObjectId,
        ref:'SecondRight'
    }]
})

const secondRightSchema = new Schema({
   _id:ObjectId,
   secondName:String,
   threeRights:[{
       type:ObjectId,
       ref:'ThreeRight'
   }]
})

const threeRightSchema = new Schema({
    _id:ObjectId,
    threeName:String
 })
const Role = model('Role', roleSchema )
const Rightance = model('Rightance', rightanceSchema )
const SecondRight = model('SecondRight', secondRightSchema)
const ThreeRight = model('ThreeRight', threeRightSchema)

module.exports =  { Role, Rightance, SecondRight, ThreeRight }